package com.ymatou.iapi.godmch.testcase;

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.bindmchBean;
import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.createIndepMchBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.service.SetPayModeCall;
import com.ymatou.iapi.godmch.service.bindmchCall;
import com.ymatou.iapi.godmch.service.CreateCodeCall;
import com.ymatou.iapi.godmch.service.createIndepMchCall;
import com.ymatou.iapi.godmch.service.createSupplierCodeCall;
import com.ymatou.iapi.godmch.service.createmchCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.agent_type;
import com.ymttest.database.model.invite_code;
import com.ymttest.database.model.mch_info;
import com.ymttest.database.model.mch_relation;
import com.ymttest.database.sqlwapper.godmch.agent_typeWapper;
import com.ymttest.database.sqlwapper.godmch.country_infoWapper;
import com.ymttest.database.sqlwapper.godmch.invite_codeWapper;
import com.ymttest.database.sqlwapper.godmch.mch_infoWapper;
import com.ymttest.database.sqlwapper.godmch.mch_relationWapper;
import com.ymttest.utils.TestDataManager;
/**
*绑定商户关系
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_bindmch{
	private static bindmchBean bean;
	private static bindmchCall call;
	private  createmchBean createmchbean=new createmchBean();
	private  createmchCall createmchcall=new createmchCall();
	
    public  agent_typeWapper agentTypeWapper=new agent_typeWapper();
	private static mch_infoWapper mchInfoWapper=new mch_infoWapper();
	private static country_infoWapper countryinfoWapper=new country_infoWapper();
	private static invite_codeWapper invitecodeWapper=new invite_codeWapper();
	private static mch_relationWapper mchrelationWapper=new mch_relationWapper();
	private static agent_typeWapper agenttypeWapper=new agent_typeWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("绑定商户关系");
	}

	@Before
	public void caseUp() {
		bean=new bindmchBean();
		call=new bindmchCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_bindmch_001() {
		Logger.start(true,"绑定商户关系-商户Id和邀请码同时存在-自主选货-返回成功");
		try {
            //渠道商1
			int userId1=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId1);
			createmchbean.setCountry("USA");
			createmchbean.setNickName("商户昵称_"+TestDataManager.getPhoneNum());
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			//渠道商2
			int userId2=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId2);
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			//渠道商1邀请码
			CreateCodeBean createbean=GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall=GodmchManageCallService.createCodeCall(createbean);
			//代理
			bean.setMchId(userId2);
			bean.setCode(createcall.getCode());
			call.setData(bean);
			call.callService();	
			
			checkverify(userId2,userId1);      
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_bindmch_001_1() {
		Logger.start(true,"绑定商户关系-商户Id和邀请码同时存在-自动继承-返回失败(两个海外纯渠道不能成为继承模式代理商)");
		try {
            //渠道商1
			int userId1=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId1);
			createmchbean.setCountry("USA");
			createmchbean.setNickName("商户昵称_"+TestDataManager.getPhoneNum());
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			//渠道商2
			int userId2=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId2);
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			//渠道商1邀请码
			CreateCodeBean createbean=GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			createbean.setAgentModel(2);//自动继承
			CreateCodeCall createcall=GodmchManageCallService.createCodeCall(createbean);
			//代理
			bean.setMchId(userId2);
			bean.setCode(createcall.getCode());
			call.setData(bean);
			call.callService();	
			
			//checkverify(userId2,userId1);
			Logger.verifyEquals("5000", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals(true, call.getMessage().contains("继承型代理目前仅支持中国大陆商户"), "验证返回成功Message值");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	

	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_bindmch_002() {
		Logger.start(true,"绑定商户关系-商户Id和邀请码同时存在-代理商与渠道商的结算币种不一致-返回错误(现在返回成功 跨国20191023修改)");
		try {

            //渠道商1
			int userId1=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId1);
			createmchbean.setCountry("USA");
			createmchbean.setNickName("商户昵称_"+TestDataManager.getPhoneNum());
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			//渠道商2
			int userId2=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId2);
			createmchbean.setCountry("BEL");
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			//邀请码
			CreateCodeBean createbean=GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall=GodmchManageCallService.createCodeCall(createbean);
			//代理
			bean.setMchId(userId2);
			bean.setCode(createcall.getCode());
			call.setData(bean);
			call.callService();	
			
			checkverify(userId2,userId1);    
			
//	        Logger.verifyEquals("5018", call.getStatusCode1(), "验证返回成功status值");
//	        Logger.verifyEquals(true, call.getMessage().contains("结算币种与上级商户不一致"), "验证返回成功Message值");  		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_bindmch_003() {
		Logger.start(true,"绑定商户关系-商户Id不存在-返回错误");
		try {

			 //渠道商1
			int userId1=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId1);
			createmchbean.setCountry("USA");
			createmchbean.setNickName("商户昵称_"+TestDataManager.getPhoneNum());
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			//邀请码
			CreateCodeBean createbean=GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall=GodmchManageCallService.createCodeCall(createbean);
			//代理
			bean.setMchId(9999);
			bean.setCode(createcall.getCode());
			call.setData(bean);
			call.callService();	
			
	        Logger.verifyEquals("5004", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals(true, call.getMessage().contains("商户不存在"), "验证返回成功Message值");  					
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_bindmch_004() {
		Logger.start(true,"绑定商户关系-邀请码不存在-返回错误");
		try {

			//渠道商1
			int userId1=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId1);
			createmchbean.setCountry("USA");
			createmchbean.setNickName("商户昵称_"+TestDataManager.getPhoneNum());
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			//渠道商2
			int userId2=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId2);
			createmchbean.setCountry("BEL");
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			//代理
			bean.setMchId(userId2);
			bean.setCode("99995454564412154");
			call.setData(bean);
			call.callService();	
			
	        Logger.verifyEquals("5011", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals(true, call.getMessage().contains("邀请码不存在"), "验证返回成功Message值");  		
					
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_bindmch_005() {
		Logger.start(true,"绑定商户关系-邀请码过期-返回错误");
		try {

			//渠道商1
			int userId1=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId1);
			createmchbean.setCountry("USA");
			createmchbean.setNickName("商户昵称_"+TestDataManager.getPhoneNum());
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			//渠道商2
			int userId2=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId2);
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			//邀请码
			CreateCodeBean createbean=GodmchManageCallService.InitcreateCodeBeanForAgent(userId1,false);
			CreateCodeCall createcall=GodmchManageCallService.createCodeCall(createbean);
			//修改过期时间
			Date date = new Date();
			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	        java.util.Calendar Cal=java.util.Calendar.getInstance();   
	        Cal.setTime(date);   
	        Cal.add(java.util.Calendar.DAY_OF_YEAR,-1);  //目前配置一天后过期 
	        
	        Date currentTime_2 = format.parse(format.format(Cal.getTime()));
			invitecodeWapper.updateExpireByCode(createcall.getCode(), currentTime_2);
			//代理
			bean.setMchId(userId2);
			bean.setCode(createcall.getCode());
			call.setData(bean);
			call.callService();	
			
	        Logger.verifyEquals("5016", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals(true, call.getMessage().contains("邀请码已失效"), "验证返回成功Message值");  			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_bindmch_006() {
		Logger.start(true,"绑定商户关系-vip渠道绑定普通渠道-返回成功");
		try {
            //渠道商1
			int userId1=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId1);
			createmchbean.setCountry("USA");
			createmchbean.setNickName("商户昵称_"+TestDataManager.getPhoneNum());
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			//修改vip代理
			Map<String,Object> map=new HashMap();
			map.put("mchId", userId1);
			mch_info mchInfo=mchInfoWapper.selectby(map).get(0);
			mchInfo.setVip(1);
			mchInfoWapper.updateByPrimaryKey(mchInfo);
			//渠道商2
			int userId2=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId2);
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			//渠道商1邀请码
			CreateCodeBean createbean=GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall=GodmchManageCallService.createCodeCall(createbean);
			
			bean.setMchId(userId2);
			bean.setCode(createcall.getCode());
			call.setData(bean);
			call.callService();			  
	      //mch_relation
	        List<mch_relation> mchrelations=mchrelationWapper.selectByPrimaryKey(userId2, userId1);
	        for(mch_relation relation:mchrelations)
	        {
	           	//agent_type
		        Map<String,Object> map2=new HashMap();
		        map2.put("mchId", relation.getParentMchId());
		        map2.put("agentType", relation.getAgentType());
		        List<agent_type>  agenttypeList =agenttypeWapper.selectby(map);
		        Logger.verifyEquals(true,agenttypeList.size()>0, "验证数据库mch_relation对应的 一级代理 字段agentType 存在");
				//invite_code
		        Map<String,Object> map3=new HashMap();
		        map3.put("mchId", relation.getParentMchId());
		        map3.put("inviteCode", relation.getInviteCode());
		        List<invite_code> inviteCodeList=invitecodeWapper.selectby(map3);
		        Logger.verifyEquals(true,inviteCodeList.size()>0, "验证数据库mch_relation对应的 一级代理 字段inviteCode 存在");
		        
		        Logger.verifyEquals(userId1,relation.getParentMchId(), "验证数据库mch_relation对应的 ParentMchId字段是否正确");
		        Logger.verifyEquals(userId2,relation.getMchId(), "验证数据库mch_relation对应的 MchId字段是否正确");
	        } 
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_bindmch_007() {
		Logger.start(true,"绑定商户关系-vip代理绑定普通代理-返回成功");
		try {
			Logger.comment("##########创建vip代理  开始  ###############");
			createmchBean mchBean=new createmchBean();
			createmchCall mchCall=new createmchCall();
			UserCreateBean usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean);
			//创建渠道
			mchBean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(mchBean);	
            //设置vip
			GodmchManageCallService.SetVip(userId_channl);
			//渠道商邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(userId_channl);
			CreateCodeCall createcall=GodmchManageCallService.createCodeCall(createCodeBean);
			//vip代理
			mchBean=new createmchBean();
		    usercreateBean=DGUserCallService.initUsercreateBean();
			int vipuserId_agent1=DGUserCallService.UserCreateCall(usercreateBean);
			
			mchBean.setMchId(vipuserId_agent1);
			mchBean.setCode(createcall.getCode());
			mchBean.setCountry("USA");
			mchBean.setNickName("商户昵称_"+TestDataManager.getPhoneNum());
			GodmchManageCallService.createmchCallForAgent(mchBean);

			//vip代理邀请码
		    createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(vipuserId_agent1);
		    CreateCodeCall vipcreatecall=GodmchManageCallService.createCodeCall(createCodeBean);
			Logger.comment("##########创建vip代理  结束  ###############");
			
			Logger.comment("##########创建普通代理 开始  ###############");
		    usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_channl2=DGUserCallService.UserCreateCall(usercreateBean);
			//创建渠道
			mchBean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl2);
			GodmchManageCallService.createmchCallForChannel(mchBean);	
			//渠道商邀请码
			CreateCodeBean createCodeBean2=GodmchManageCallService.InitcreateCodeBeanForAgent(userId_channl2);
			CreateCodeCall createcall2=GodmchManageCallService.createCodeCall(createCodeBean2);
			//普通代理
			mchBean=new createmchBean();
		    usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_agent1=DGUserCallService.UserCreateCall(usercreateBean);
			
			mchBean.setMchId(userId_agent1);
			mchBean.setCode(createcall2.getCode());
			mchBean.setCountry("USA");
			mchBean.setNickName("商户昵称_"+TestDataManager.getPhoneNum());
			GodmchManageCallService.createmchCallForAgent(mchBean);
			Logger.comment("##########创建普通代理  结束  ###############");
			bean.setMchId(userId_agent1);
			bean.setCode(vipcreatecall.getCode());
			call.setData(bean);
			call.callService();			
			
			//验证vip渠道  vip代理
			Map<String,Object> map=new HashMap();
			map.put("mchId", userId_channl);
			mch_info mchInfo=mchInfoWapper.selectby(map).get(0);
	        Logger.verifyEquals(0, mchInfo.getAgent(), "验证数据库mch_info对应的字段Agent");
	        Logger.verifyEquals(1, mchInfo.getChannels(), "验证数据库mch_info对应的字段Channel");
	        Logger.verifyEquals(1, mchInfo.getVip(), "验证数据库mch_info对应的字段Vip");
	        Logger.comment("########### vip渠道 与vip代理   #######################");
	        mch_relation mchrelation= mchrelationWapper.selectByPrimaryKey(vipuserId_agent1, userId_channl).get(0);
	        Logger.verifyEquals(createcall.getCode(), mchrelation.getInviteCode(), "验证数据库mch_info对应的字段InviteCode");
	        Logger.verifyEquals(1, mchrelation.getAddSubAgent(), "验证数据库mch_info对应的字段AddSubAgent");
	        
			//验证普通渠道 代理
	        Logger.comment("########### 普通渠道 与普通代理   #######################");
		    map=new HashMap();
			map.put("mchId", userId_channl);
		    mchInfo=mchInfoWapper.selectby(map).get(0);
	        Logger.verifyEquals(0, mchInfo.getAgent(), "验证数据库mch_info对应的字段Agent");
	        Logger.verifyEquals(1, mchInfo.getChannels(), "验证数据库mch_info对应的字段Channel");
	        Logger.verifyEquals(1, mchInfo.getVip(), "验证数据库mch_info对应的字段Vip");
	        mchrelation= mchrelationWapper.selectByPrimaryKey(userId_agent1,userId_channl2).get(0);
	        Logger.verifyEquals(createcall2.getCode(), mchrelation.getInviteCode(), "验证数据库mch_info对应的字段InviteCode");
	        Logger.verifyEquals(0, mchrelation.getAddSubAgent(), "验证数据库mch_info对应的字段AddSubAgent");
	        //验证vip代理与普通代理
	        Logger.comment("########### vip代理与普通代理   #######################");
	        mchrelation= mchrelationWapper.selectByPrimaryKey(userId_agent1,vipuserId_agent1).get(0);
	        Logger.comment("#########"+userId_agent1);
	        Logger.comment("#########"+vipuserId_agent1);
	        Logger.verifyEquals(vipcreatecall.getCode(), mchrelation.getInviteCode(), "验证数据库mch_info对应的字段InviteCode");
	        Logger.verifyEquals(1, mchrelation.getAddSubAgent(), "验证数据库mch_info对应的字段AddSubAgent");
		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_bindmch_008() {
		Logger.start(true,"绑定商户关系-vip代理绑定vip代理-返回成功");
		try {
			Logger.comment("##########创建vip代理  开始  ###############");
			createmchBean mchBean=new createmchBean();
			createmchCall mchCall=new createmchCall();
			UserCreateBean usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean);
			//创建渠道
			mchBean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(mchBean);	
            //设置vip
			GodmchManageCallService.SetVip(userId_channl);
			//渠道商邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(userId_channl);
			CreateCodeCall createcall=GodmchManageCallService.createCodeCall(createCodeBean);
			//vip代理
			mchBean=new createmchBean();
		    usercreateBean=DGUserCallService.initUsercreateBean();
			int vipuserId_agent1=DGUserCallService.UserCreateCall(usercreateBean);
			
			mchBean.setMchId(vipuserId_agent1);
			mchBean.setCode(createcall.getCode());
			mchBean.setCountry("USA");
			mchBean.setNickName("商户昵称_"+TestDataManager.getPhoneNum());
			GodmchManageCallService.createmchCallForAgent(mchBean);

			//vip代理邀请码
		    createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(vipuserId_agent1);
		    CreateCodeCall vipcreatecall=GodmchManageCallService.createCodeCall(createCodeBean);
			Logger.comment("##########创建vip代理  结束  ###############");
			
			
			Logger.comment("##########创建普通代理  开始  ###############");
		    usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_channl2=DGUserCallService.UserCreateCall(usercreateBean);
			//创建渠道
			mchBean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl2);
			GodmchManageCallService.createmchCallForChannel(mchBean);	
			//渠道商邀请码
		    createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(userId_channl2);
			createcall=GodmchManageCallService.createCodeCall(createCodeBean);
			//vip代理
			mchBean=new createmchBean();
		    usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_agent2=DGUserCallService.UserCreateCall(usercreateBean);
			
			mchBean.setMchId(userId_agent2);
			mchBean.setCode(createcall.getCode());
			mchBean.setCountry("USA");
			mchBean.setNickName("商户昵称_"+TestDataManager.getPhoneNum());
			GodmchManageCallService.createmchCallForAgent(mchBean);
			
		    createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(userId_agent2);
		    CreateCodeCall createcodecall=GodmchManageCallService.createCodeCall(createCodeBean);
			Logger.comment("##########创建vip代理  结束  ###############");
			
			bean.setMchId(userId_agent2);//vip代理userid
			bean.setCode(vipcreatecall.getCode());//vip代理邀请码code
			call.setData(bean);
			call.callService();			
			
			mch_relation mchrelation= mchrelationWapper.selectByPrimaryKey(userId_agent2,vipuserId_agent1).get(0);
	        Logger.comment("#########"+userId_agent2);
	        Logger.comment("#########"+vipuserId_agent1);
	        Logger.verifyEquals(vipcreatecall.getCode(), mchrelation.getInviteCode(), "验证数据库mch_info对应的字段InviteCode");
	        Logger.verifyEquals(1, mchrelation.getAddSubAgent(), "验证数据库mch_info对应的字段AddSubAgent");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_bindmch_009() {
		Logger.start(true,"绑定商户关系-vip代理绑定vip渠道-返回成功");
		try {
			Logger.comment("##########创建vip代理  开始  ###############");
			createmchBean mchBean=new createmchBean();
			createmchCall mchCall=new createmchCall();
			UserCreateBean usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean);
			//创建渠道
			mchBean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(mchBean);	
            //设置vip
			GodmchManageCallService.SetVip(userId_channl);
			//渠道商邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(userId_channl);
			CreateCodeCall createcall=GodmchManageCallService.createCodeCall(createCodeBean);
			//vip代理
			mchBean=new createmchBean();
		    usercreateBean=DGUserCallService.initUsercreateBean();
			int vipuserId_agent1=DGUserCallService.UserCreateCall(usercreateBean);
			
			mchBean.setMchId(vipuserId_agent1);
			mchBean.setCode(createcall.getCode());
			mchBean.setCountry("USA");
			mchBean.setNickName("商户昵称_"+TestDataManager.getPhoneNum());
			GodmchManageCallService.createmchCallForAgent(mchBean);

			//vip代理邀请码
		    createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(vipuserId_agent1);
		    CreateCodeCall vipcreatecall=GodmchManageCallService.createCodeCall(createCodeBean);
			Logger.comment("##########创建vip代理  结束  ###############");
			
			Logger.comment("##########创建vip渠道  开始  ###############");
		    usercreateBean=DGUserCallService.initUsercreateBean();
			int vipuserId_channl2=DGUserCallService.UserCreateCall(usercreateBean);
			//创建渠道
			mchBean=GodmchManageCallService.InitcreatemchBeanForChannel(vipuserId_channl2);
			GodmchManageCallService.createmchCallForChannel(mchBean);	
            //设置vip
			GodmchManageCallService.SetVip(vipuserId_channl2);
			//渠道商邀请码
			CreateCodeBean createCodeBean2=GodmchManageCallService.InitcreateCodeBeanForAgent(vipuserId_channl2);
			CreateCodeCall createcall2=GodmchManageCallService.createCodeCall(createCodeBean2);
			Logger.comment("##########创建vip渠道  结束  ###############");
			
			bean.setMchId(vipuserId_agent1);
			bean.setCode(createcall2.getCode());
			call.setData(bean);
			call.callService();			
			
			//验证第一个vip渠道 1
			Map<String,Object> map=new HashMap();
			map.put("mchId", userId_channl);
			mch_info mchInfo=mchInfoWapper.selectby(map).get(0);
	        Logger.verifyEquals(0, mchInfo.getAgent(), "验证数据库mch_info对应的字段Agent");
	        Logger.verifyEquals(1, mchInfo.getChannels(), "验证数据库mch_info对应的字段Channel");
	        Logger.verifyEquals(1, mchInfo.getVip(), "验证数据库mch_info对应的字段Vip");
	        mch_relation mchrelation= mchrelationWapper.selectByPrimaryKey(vipuserId_agent1, userId_channl).get(0);
	        Logger.verifyEquals(createcall.getCode(), mchrelation.getInviteCode(), "验证数据库mch_info对应的字段InviteCode");
	        Logger.verifyEquals(1, mchrelation.getAddSubAgent(), "验证数据库mch_info对应的字段AddSubAgent");
	        
			//验证第一个vip渠道 2
		    map=new HashMap();
			map.put("mchId", userId_channl);
		    mchInfo=mchInfoWapper.selectby(map).get(0);
	        Logger.verifyEquals(0, mchInfo.getAgent(), "验证数据库mch_info对应的字段Agent");
	        Logger.verifyEquals(1, mchInfo.getChannels(), "验证数据库mch_info对应的字段Channel");
	        Logger.verifyEquals(1, mchInfo.getVip(), "验证数据库mch_info对应的字段Vip");
	        mchrelation= mchrelationWapper.selectByPrimaryKey(vipuserId_agent1,vipuserId_channl2).get(0);
	        Logger.verifyEquals(createcall2.getCode(), mchrelation.getInviteCode(), "验证数据库mch_info对应的字段InviteCode");
	        Logger.verifyEquals(1, mchrelation.getAddSubAgent(), "验证数据库mch_info对应的字段AddSubAgent");
	      //mch_relation

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_bindmch_010() {
		Logger.start(true,"绑定商户关系-vip渠道绑定vip渠道-返回成功");
		try {
			Logger.comment("##########创建vip渠道1  开始  ###############");
			//渠道商1
			int userId1=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId1);
			createmchbean.setCountry("USA");
			createmchbean.setNickName("商户昵称_"+TestDataManager.getPhoneNum());
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			//修改vip字段
			GodmchManageCallService.SetVip(userId1);
			Logger.comment("##########创建vip渠道1 结束 ###############");
			
			Logger.comment("##########创建vip渠道2  开始  ###############");
			//渠道商2
			int userId2=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId2);
			
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			//修改vip代理
			GodmchManageCallService.SetVip(userId2);
			Logger.comment("##########创建vip渠道2  结束  ###############");
			//渠道商1邀请码
			CreateCodeBean createbean=GodmchManageCallService.InitcreateCodeBeanForAgent(userId2);
			CreateCodeCall createcall=GodmchManageCallService.createCodeCall(createbean);
			
			bean.setMchId(userId1);
			bean.setCode(createcall.getCode());
			call.setData(bean);
			call.callService();			
			
	        mch_relation mchrelation= mchrelationWapper.selectByPrimaryKey(userId1, userId2).get(0);
	        Logger.verifyEquals(createcall.getCode(), mchrelation.getInviteCode(), "验证数据库mch_info对应的字段InviteCode");
	        Logger.verifyEquals(1, mchrelation.getAddSubAgent(), "验证数据库mch_info对应的字段AddSubAgent");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_bindmch_010_1() {
		Logger.start(true,"绑定商户关系-普通渠道绑定普通渠道-返回成功");
		try {
			Logger.comment("##########创建vip渠道1  开始  ###############");
			//渠道商1
			int userId1=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId1);
			createmchbean.setCountry("USA");
			createmchbean.setNickName("商户昵称_"+TestDataManager.getPhoneNum());
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			//修改vip字段
		//	GodmchManageCallService.SetVip(userId1);
			Logger.comment("##########创建vip渠道1 结束 ###############");
			
			Logger.comment("##########创建vip渠道2  开始  ###############");
			//渠道商2
			int userId2=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId2);
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			//修改vip代理
			//GodmchManageCallService.SetVip(userId2);
			Logger.comment("##########创建vip渠道2  结束  ###############");
			//渠道商1邀请码
			CreateCodeBean createbean=GodmchManageCallService.InitcreateCodeBeanForAgent(userId2);
			CreateCodeCall createcall=GodmchManageCallService.createCodeCall(createbean);
			
			bean.setMchId(userId1);
			bean.setCode(createcall.getCode());
			call.setData(bean);
			call.callService();			
			
	        mch_relation mchrelation= mchrelationWapper.selectByPrimaryKey(userId1, userId2).get(0);
	        Logger.verifyEquals(createcall.getCode(), mchrelation.getInviteCode(), "验证数据库mch_info对应的字段InviteCode");
	        Logger.verifyEquals(0, mchrelation.getAddSubAgent(), "验证数据库mch_info对应的字段AddSubAgent");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_bindmch_011() {
		Logger.start(true,"绑定商户关系-商户不能重复绑定代理-商户绑定了二级代理，再绑定一级代理-返回失败");
		try {
            //渠道商1
			int userId1=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId1);
			createmchbean.setCountry("USA");
			createmchbean.setNickName("商户昵称_"+TestDataManager.getPhoneNum());
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			//渠道商2
			int userId2=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId2);
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			//渠道商1邀请码1
			CreateCodeBean createbean=GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall=GodmchManageCallService.createCodeCall(createbean);
			//渠道商1邀请码2
			createbean=GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			createbean.setIsPermanently(false);
			CreateCodeCall createcall2=GodmchManageCallService.createCodeCall(createbean);
			//第一次绑定
			bean.setMchId(userId2);
			bean.setCode(createcall.getCode());
			call.setData(bean);
			call.callService();	
			//第二次绑定
			bean.setCode(createcall2.getCode());
			call.setData(bean);
			call.callService();	
			
	        Logger.verifyEquals("5033", call.getStatusCode1(), "验证返回成功status值");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_bindmch_012() {
		Logger.start(true,"绑定商户关系-渠道支付类型是盛付通-绑定非盛付通代理-返回失败");
		try {
            //渠道商1
			int userId1=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId1);
			createmchbean.setCountry("USA");
			createmchbean.setNickName("商户昵称_"+TestDataManager.getPhoneNum());
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			
			SetPayModeCall SetPayModeCall=GodmchManageCallService.SetPayMode(userId1);
			//渠道商2
			int userId2=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId2);
			//createmchbean.setCountry("CHN");
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			//渠道商1邀请码1
			CreateCodeBean createbean=GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall=GodmchManageCallService.createCodeCall(createbean);
			//绑定
			bean.setMchId(userId2);
			bean.setCode(createcall.getCode());
			call.setData(bean);
			call.callService();	
			
	       Logger.verifyEquals("5000", call.getStatusCode1(), "验证返回成功status值");
	       Logger.verifyEquals(true, call.getMessage().contains("支付通道不匹配"), "验证返回成功message值");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_bindmch_013() {
		Logger.start(true,"绑定商户关系-渠道、代理 支付类型都是盛付通-返回失败");
		try {
            //渠道商1
			int userId1=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId1);
			createmchbean.setCountry("USA");
			createmchbean.setNickName("商户昵称_"+TestDataManager.getPhoneNum());
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			//设置渠道支付类型是盛付通
			GodmchManageCallService.SetPayMode(userId1);
			//渠道商2
			int userId2=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId2);
			//createmchbean.setCountry("CHN");
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			//设置代理支付类型是盛付通
			GodmchManageCallService.SetPayMode(userId2);
			//渠道商1邀请码1
			CreateCodeBean createbean=GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall=GodmchManageCallService.createCodeCall(createbean);
			//绑定
			bean.setMchId(userId2);
			bean.setCode(createcall.getCode());
			call.setData(bean);
			call.callService();	
			
			checkverify(userId2,userId1);      
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_bindmch_0014() {
		Logger.start(true,"绑定商户关系-一个代理两个渠道");
		try {
            //渠道商1
			int userId1=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId1);
			createmchbean.setCountry("USA");
			createmchbean.setNickName("商户昵称_"+TestDataManager.getPhoneNum());
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			//渠道商2
			int userId2=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId2);
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			//渠道商1邀请码
			CreateCodeBean createbean=GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall=GodmchManageCallService.createCodeCall(createbean);
			
			//渠道商2邀请码
			CreateCodeBean createbean2=GodmchManageCallService.InitcreateCodeBeanForAgent(userId2);
			CreateCodeCall createcall2=GodmchManageCallService.createCodeCall(createbean2);
			
			
			//代理
			int userId3=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId3);
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			
			//代理
			bean.setMchId(userId3);
			bean.setCode(createcall.getCode());
			call.setData(bean);
			call.callService();	
			
			//代理
			bean.setMchId(userId3);
			bean.setCode(createcall2.getCode());
			call.setData(bean);
			call.callService();	
			
			//checkverify(userId2,userId1);
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_bindmch_015() {
		Logger.start(true,"绑定商户关系-验证独立供货商邀请码绑定平台商户-返回失败");
		try {

			 //渠道商1
			int userId1=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId1);
			createmchbean.setCountry("USA");
			createmchbean.setNickName("商户昵称_"+TestDataManager.getPhoneNum());
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			//邀请码
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            
			createSupplierCodeCall createSupplierCodeCall=GodmchManageCallService.createSupplierCode(createIndepMchCall.getmchId());
			//代理
			bean.setMchId(userId1);
			//bean.setCode(createcall.getCode());
			bean.setCode(createSupplierCodeCall.getCode());
			call.setData(bean);
			call.callService();	
			
	        Logger.verifyEquals("5011", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals(true, call.getMessage().contains("邀请码不存在"), "验证返回成功Message值");  					
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	public void checkverify(int mchId,int parentMchId ) throws InterruptedException, JSONException
	{
		Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
        Logger.verifyEquals(true, call.getSuccess(), "验证返回成功success值");
        
        //mch_relation
        List<mch_relation> mchrelations=mchrelationWapper.selectByPrimaryKey(mchId, parentMchId);
        for(mch_relation relation:mchrelations)
        {
           	//agent_type
	        Map<String,Object> map2=new HashMap();
	        map2.put("mchId", relation.getParentMchId());
	        map2.put("agentType", relation.getAgentType());
	        List<agent_type>  agenttypeList =agenttypeWapper.selectby(map2);
	        Logger.verifyEquals(true,agenttypeList.size()>0, "验证数据库mch_relation对应的 一级代理 字段agentType 存在");
			//invite_code
	        Map<String,Object> map3=new HashMap();
	        map3.put("mchId", relation.getParentMchId());
	        map3.put("inviteCode", relation.getInviteCode());
	        List<invite_code> inviteCodeList=invitecodeWapper.selectby(map3);
	        Logger.verifyEquals(true,inviteCodeList.size()>0, "验证数据库mch_relation对应的 一级代理 字段inviteCode 存在");
	        //mch_relation
	        Logger.verifyEquals(relation.getAgentType(),agenttypeList.get(0).getAgentType(), "验证数据库mch_relation中的AgentType");
	        
	        Logger.verifyEquals(relation.getInviteCode(),inviteCodeList.get(0).getInviteCode(), "验证数据库mch_relation中的InviteCode");
	        Logger.verifyEquals(relation.getAgentModel(),inviteCodeList.get(0).getAgentModel(), "验证数据库mch_relation中的AgentModel");
        }
	}
}